<template>
	<view>
		<u-cell-group>
			<u-cell-item title="头像">
				<u-upload :deletable='false' ref='file' :max-count='1' :custom-btn="true" slot="right-icon"
					:file-list='files' @on-change='onChange' :action="action" :header='header'>
					<u-image slot="addBtn" border-radius="50%" width="100rpx" height="100rpx" :src="userInfo.handlUrl">
					</u-image>
				</u-upload>

			</u-cell-item>
			<u-cell-item @click='handNavTo' title="昵称" :value="userInfo.nickName"></u-cell-item>
			<u-cell-item title="手机号" :value="userInfo.telPhone"></u-cell-item>
		</u-cell-group>
	</view>
</template>

<script>
	import cacheFunc from '@/utils/cache.js'
	import {
		baseURL
	} from '@/config/config.js'
	export default {
		data() {
			return {
				files: [],
				userInfo: {},
				action: baseURL + 'appUser/uploadImg',
				header: {
					token: cacheFunc.getCache('busToken') || ''
				},
			};
		},
		onLoad() {
			// GET /app/appUser/updateHandlImg
			const userInfo = this.cache.getCache('busUserInfo')
			this.userInfo = userInfo
			console.log(userInfo)
		},
		methods: {
			handNavTo() {
				uni.navigateTo({
					url: '/pages/userMsg/editName/editName?name=' + this.userInfo.nickName
				})
			},
			async onChange(res, index, lists, name) {
				const data = res.data && JSON.parse(res.data).data
				await this.$u.api.updateHandlImg({
					handlUrl: data
				})
				uni.showToast({
					title: '修改成功',
					icon: 'success'
				})
				this.userInfo.handlUrl = data
				this.cache.setCache('busUserInfo', this.userInfo)
				this.$refs.file.clear()
			}
		}
	}
</script>

<style lang="scss">

</style>
